package com.ugrow.ugrowcommunity.vm.forum;

import androidx.lifecycle.ViewModelProviders;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.os.Parcelable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Toast;


import com.ugrow.ugrowcommunity.activity.web.WebActivity;
import com.ugrow.ugrowcommunity.databinding.ForumFragmentBinding;
import com.ugrow.ugrowcommunity.util.InitBean;
import com.ugrow.ugrowcommunity.vm.base.BaseFragment;
import com.ugrow.ugrowcommunity.vm.forum.adapter.RecruitAdapter;
import com.ugrow.ugrowcommunity.vm.forum.bean.RecruitBean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class ForumFragment extends BaseFragment<ForumFragmentBinding,ForumViewModel> {


   // binding 和 mViewModel 可以直接使用,无需声明;

    public static ForumFragment newInstance() {
        return new ForumFragment();
    }


    @Override
    protected ForumFragmentBinding setContentView(LayoutInflater inflater, @Nullable ViewGroup container) {
        return ForumFragmentBinding.inflate(inflater, container, false);
    }

    @Override
    protected ForumViewModel setViewModel() {
        return ViewModelProviders.of(this).get(ForumViewModel.class);
    }

    @Override
    protected void onVisible() {

    }

    @Override
    protected void onFirstLoad() {

        List<RecruitBean> recruitBeans = InitBean.getForumList();

        RecruitAdapter adapter = new RecruitAdapter(getActivity(),recruitBeans);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        binding.recruitRlv.setAdapter(adapter);
        binding.recruitRlv.setLayoutManager(layoutManager);
        adapter.setOnItemClick(new RecruitAdapter.OnItemClick() {
            @Override
            public void onClick(int position) {
                Intent intent = new Intent(getActivity(), WebActivity.class);
                intent.putExtra("title",recruitBeans.get(position).getName());
                intent.putExtra("url",recruitBeans.get(position).getUrl());
                startActivity(intent);
            }
        });

    }




}